#ifndef SDK_OHOS_API_OHOS_DATA_CHANNEL_INTERFACE_H_
#define SDK_OHOS_API_OHOS_DATA_CHANNEL_INTERFACE_H_

#include "api/ref_count.h"
#include "api/rtp_parameters.h"
#include "api/data_channel_interface.h"

namespace ohoswebrtc {

class OHOSDataChannelObserver {
 public:
  /** The data channel state have changed.*/
  virtual void OnStateChange() = 0;

  /** A data buffer was successfully received.*/
  virtual void OnMessage(const webrtc::DataBuffer& buffer) = 0;

  /** The data channel's buffered_amount has changed.*/
  virtual void OnBufferedAmountChange(uint64_t sent_data_size) {}

 protected:
  virtual ~OHOSDataChannelObserver() = default;
};

class OHOSDataChannelInterface : public webrtc::RefCountInterface {
 public:

  /** The label attribute represents a label that can be used to distinguish this
   *  DataChannel object from other DataChannel objects
   */
  virtual std::string label() const = 0;

  /** The accessors below simply return the properties from the DataChannelInit.
   * the data channel was constructed with.
   */
  virtual bool reliable() const = 0;

  virtual bool ordered() const = 0;

  virtual uint16_t maxRetransmitTime() const = 0;
  virtual uint16_t maxRetransmits() const = 0;
  virtual absl::optional<int> maxRetransmitsOpt() const = 0;
  virtual absl::optional<int> maxPacketLifeTime() const = 0;
  virtual std::string protocol() const = 0;
  virtual bool negotiated() const = 0;

  /** Returns the ID from the DataChannelInit, if it was negotiated out-of-band.
   * If negotiated in-band, this ID will be populated once the DTLS role is
   * determined, and until then this will return -1.
   */
  virtual int id() const = 0;
  
  /** The state of the data channel.*/
  virtual webrtc::DataChannelInterface::DataState state() const = 0;
  
  virtual uint32_t messages_sent() const = 0;
  virtual uint64_t bytes_sent() const = 0;
  virtual uint32_t messages_received() const = 0;
  virtual uint64_t bytes_received() const = 0;
  
  /** The number of bytes of application data that have been queued using 
   *`sendData:` but that have not yet been transmitted to the network.
   */
  virtual uint64_t buffered_amount() const = 0;

  /** Begins the graceful data channel closing procedure. */
  virtual void Close() = 0;

  /** Sends `data` to the remote peer. If the data can't be sent at the SCTP
   * level (due to congestion control), it's buffered at the data channel level,
   * up to a maximum of MaxSendQueueSize().
   * Returns false if the data channel is not in open state or if the send
   * buffer is full.
   */
  virtual void Send(const webrtc::DataBuffer& buffer) = 0;

  virtual void Send(const uint8_t* data, uint32_t size,
                    bool binary = false) = 0;
  
  virtual void SendAsync(webrtc::DataBuffer buffer,
                         absl::AnyInvocable<void(webrtc::RTCError) &&> on_complete) = 0;

  virtual void RegisterObserver(OHOSDataChannelObserver* observer) = 0;

  virtual void UnRegisterObserver() = 0;
};

} 

#endif  // 
